home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Frameworks / Hsoi's App Shell 1.0a4 / HAS Other Source / WASTE 1.3a4 Distribution / WASTE 1.3a4 / Source / WEICGlue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-18  |  5.8 KB  |  269 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    WEICGlue.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *  Internet Config Glue
  6.  *
  7.  *  Copyright (c) 1993-1997 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  *  C port by Dan Crevier
  11.  *
  12.  */
  13.  
  14. #ifndef __ICAPI__
  15. #include "ICAPI.h"
  16. #endif
  17.  
  18. #ifndef __ICCOMPONENTSELECTORS__
  19. #include "ICComponentSelectors.h"
  20. #endif
  21.  
  22. #ifndef __COMPONENTS__
  23. #include <Components.h>
  24. #endif
  25.  
  26. #ifndef __TRAPS__
  27. #include <Traps.h>
  28. #endif
  29.  
  30. #ifndef __GESTALT__
  31. #include <Gestalt.h>
  32. #endif
  33.  
  34. #ifndef __ERRORS__
  35. #include <Errors.h>
  36. #endif
  37.  
  38. //    Internet Config component type and subtype
  39.  
  40. enum
  41. {
  42.     kICComponentType = 'PREF',
  43.     kICComponentSubType = 'ICAp'
  44. };
  45.  
  46. enum
  47. {
  48.     uppCallComponentProcInfo = kPascalStackBased
  49.         | RESULT_SIZE(SIZE_CODE(sizeof(ComponentResult)))
  50.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ComponentParameters *)))
  51. };
  52.  
  53. #if ! GENERATINGCFM
  54. //    direct inline calls (classic 68K only)
  55.  
  56. extern pascal ICError ICCStartComponent ( ICInstance instance, OSType creator )
  57.     FIVEWORDINLINE ( 0x2F3C, 0x0004, kICCStart, 0x7000, _ComponentDispatch ) ;
  58. extern pascal ICError ICCStopComponent ( ICInstance instance )
  59.     FIVEWORDINLINE ( 0x2F3C, 0x0000, kICCStop, 0x7000, _ComponentDispatch ) ;
  60. extern pascal ICError ICCFindConfigFile ( ICInstance instance, SInt16 count, ICDirSpecArrayPtr folders )
  61.     FIVEWORDINLINE ( 0x2F3C, 0x0006, kICCFindConfigFile, 0x7000, _ComponentDispatch ) ;
  62. extern pascal ICError ICCParseURL ( ICInstance instance, ConstStr255Param hint, Ptr data, SInt32 len, SInt32 * selStart, SInt32 * selEnd, Handle url )
  63.     FIVEWORDINLINE ( 0x2F3C, 0x0018, kICCParseURL, 0x7000, _ComponentDispatch ) ;
  64. extern pascal ICError ICCLaunchURL ( ICInstance instance, ConstStr255Param hint, Ptr data, SInt32 len, SInt32 * selStart, SInt32 * selEnd )
  65.     FIVEWORDINLINE ( 0x2F3C, 0x0014, kICCLaunchURL, 0x7000, _ComponentDispatch ) ;
  66. #endif    // ! GENERATINGCFM
  67.  
  68. pascal ICError ICStart
  69.     (
  70.         ICInstance * instance,
  71.         OSType creator
  72.     )
  73. {
  74.     SInt32 response ;
  75.     ICInstance ic ;
  76.     ICError err ;
  77.  
  78.     * instance = nil ;
  79.  
  80.     //    make sure the Component Manager is available
  81.     if ( ( err = Gestalt ( gestaltComponentMgr, & response ) ) != noErr )
  82.     {
  83.         goto cleanup ;
  84.     }
  85.  
  86.     //    connect to Internet Config
  87.     if ( ( ic = ( ICInstance ) OpenDefaultComponent ( kICComponentType, kICComponentSubType ) ) == nil )
  88.     {
  89.         err = unimpErr ;
  90.         goto cleanup ;
  91.     }
  92.  
  93.     //    start Internet Config
  94. #if GENERATINGCFM
  95.     {
  96.         struct
  97.         {
  98.             UInt8 flags ;
  99.             UInt8 paramSize ;
  100.             SInt16 what ;
  101.             OSType creator ;
  102.             ICInstance instance ;
  103.         } params ;
  104.         params . flags = 0 ;
  105.         params . paramSize = sizeof ( creator ) ;
  106.         params . what = kICCStart ;
  107.         params . creator = creator ;
  108.         params . instance = ic ;
  109.         err = CallUniversalProc ( CallComponentUPP, uppCallComponentProcInfo, & params ) ;
  110.     }
  111. #else
  112.     err = ICCStartComponent ( ic, creator ) ;
  113. #endif
  114.  
  115.     if ( err != noErr )
  116.     {
  117.         CloseComponent ( ( ComponentInstance ) ic ) ;
  118.         goto cleanup ;
  119.     }
  120.  
  121.     //    return IC instance
  122.     * instance = ic ;
  123.  
  124.     //    clear result code
  125.     err = noErr ;
  126.  
  127. cleanup :
  128.     return err ;
  129. }
  130.  
  131. pascal ICError ICStop
  132.     (
  133.         ICInstance instance
  134.     )
  135. {
  136.     //    stop Internet Config
  137. #if GENERATINGCFM
  138.     struct
  139.     {
  140.         UInt8 flags ;
  141.         UInt8 paramSize ;
  142.         SInt16 what ;
  143.         ICInstance instance ;
  144.     } params ;
  145.     params . flags = 0 ;
  146.     params . paramSize = 0 ;
  147.     params . what = kICCStop ;
  148.     params . instance = instance ;
  149.     CallUniversalProc ( CallComponentUPP, uppCallComponentProcInfo, & params ) ;
  150. #else
  151.     ICCStopComponent ( instance ) ;
  152. #endif
  153.  
  154.     //    and release the component instance
  155.     CloseComponent ( ( ComponentInstance ) instance ) ;
  156.  
  157.     return noErr ;
  158. }
  159.  
  160. pascal ICError ICFindConfigFile
  161.     (
  162.         ICInstance instance,
  163.         SInt16 count,
  164.         ICDirSpecArrayPtr folders
  165.     )
  166. {
  167. #if GENERATINGCFM
  168.     struct
  169.     {
  170.         UInt8 flags ;
  171.         UInt8 paramSize ;
  172.         SInt16 what ;
  173.         void * folders ;
  174.         SInt16 count ;
  175.         ICInstance instance ;
  176.     } params ;
  177.     params . flags = 0 ;
  178.     params . paramSize = sizeof ( count ) + sizeof ( folders ) ;
  179.     params . what = kICCFindConfigFile ;
  180.     params . folders = folders ;
  181.     params . count = count ;
  182.     params . instance = instance ;
  183.     return CallUniversalProc ( CallComponentUPP, uppCallComponentProcInfo, & params ) ;
  184. #else
  185.     return ICCFindConfigFile ( instance, count, folders ) ;
  186. #endif
  187. }
  188.  
  189. pascal ICError ICParseURL
  190.     (
  191.         ICInstance instance,
  192.         ConstStr255Param hint,
  193.         Ptr data,
  194.         SInt32 len,
  195.         SInt32 * selStart,
  196.         SInt32 * selEnd,
  197.         Handle url
  198.     )
  199. {
  200. #if GENERATINGCFM
  201.     struct
  202.     {
  203.         UInt8 flags ;
  204.         UInt8 paramSize ;
  205.         SInt16 what ;
  206.         Handle url ;
  207.         SInt32 * selEnd ;
  208.         SInt32 * selStart ;
  209.         SInt32 len ;
  210.         Ptr data ;
  211.         ConstStr255Param hint ;
  212.         ICInstance instance ;
  213.     } params ;
  214.     params . flags = 0 ;
  215.     params . paramSize = sizeof ( hint ) + sizeof ( data ) + sizeof (len ) +
  216.         sizeof ( selStart ) + sizeof ( selEnd ) + sizeof ( url ) ;
  217.     params . what = kICCParseURL ;
  218.     params . url = url ;
  219.     params . selEnd = selEnd ;
  220.     params . selStart = selStart ;
  221.     params . len = len ;
  222.     params . data = data ;
  223.     params . hint = hint ;
  224.     params . instance = instance ;
  225.     return CallUniversalProc ( CallComponentUPP, uppCallComponentProcInfo, & params ) ;
  226. #else
  227.     return ICCParseURL ( instance, hint, data, len, selStart, selEnd, url ) ;
  228. #endif
  229. }
  230.  
  231. pascal ICError ICLaunchURL
  232.     (
  233.         ICInstance instance,
  234.         ConstStr255Param hint,
  235.         Ptr data,
  236.         SInt32 len,
  237.         SInt32 * selStart,
  238.         SInt32 * selEnd
  239.     )
  240. {
  241. #if GENERATINGCFM
  242.     struct
  243.     {
  244.         UInt8 flags ;
  245.         UInt8 paramSize ;
  246.         SInt16 what ;
  247.         SInt32 * selEnd ;
  248.         SInt32 * selStart ;
  249.         SInt32 len ;
  250.         Ptr data ;
  251.         ConstStr255Param hint ;
  252.         ICInstance instance ;
  253.     } params ;
  254.     params . flags = 0 ;
  255.     params . paramSize = sizeof ( hint ) + sizeof ( data ) + sizeof (len ) +
  256.         sizeof ( selStart ) + sizeof ( selEnd ) ;
  257.     params . what = kICCLaunchURL ;
  258.     params . selEnd = selEnd ;
  259.     params . selStart = selStart ;
  260.     params . len = len ;
  261.     params . data = data ;
  262.     params . hint = hint ;
  263.     params . instance = instance ;
  264.     return CallUniversalProc ( CallComponentUPP, uppCallComponentProcInfo, & params ) ;
  265. #else
  266.     return ICCLaunchURL ( instance, hint, data, len, selStart, selEnd ) ;
  267. #endif
  268. }
  269.